﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Server.Models;
using Server.Share;

namespace Server.Controllers.Manage
{
    /// <summary>
    /// 广告控制器
    /// </summary>
    [RoutePrefix("51API/AdsManage")]
    public class AdsManageController : ApiController
    {
        private MShare comm = new MShare();
        [Route("AdsAdd")]
        public IHttpActionResult PostAdsAdd(AdsManageModel adsManageModel,string Token)
        {
            try
            {
                comm.CheckInfo(Token);
                comm.CheckAuth(comm.manager.id, "Ads001");
                comm.adsCtrl.AdsAdd(adsManageModel);
                RetModel ret = new RetModel()
                {
                    Data = null,
                    ErrCode = "",
                    ErrInfo = "",
                    Success = true
                };
                return Ok(ret);
            }
            catch (Exception ex)
            {
                return Ok(new RetModel { Success = false, ErrCode = "AdsManage001", ErrInfo = ex.Message, Data = null });
            }
        }
        [Route("AdsEdit")]
        public IHttpActionResult PostAdsEdit(AdsManageModel adsManageModel,string Token)
        {
            try
            {
                comm.CheckInfo(Token);
                comm.CheckAuth(comm.manager.id, "Ads002");
                comm.adsCtrl.AdsEdit(adsManageModel);
                RetModel ret = new RetModel()
                {
                    Data = null,
                    ErrCode = "",
                    ErrInfo = "",
                    Success = true
                };
                return Ok(ret);
            }
            catch (Exception ex)
            {
                return Ok(new RetModel { Success = false, ErrCode = "AdsManage002", ErrInfo = ex.Message, Data = null });
            }
        }
        [Route("AdsDel")]
        public IHttpActionResult PostAdsDel(int id ,string Token)
        {
            try
            {
                comm.CheckInfo(Token);
                comm.CheckAuth(comm.manager.id, "Ads003");
                comm.adsCtrl.AdsDel(id);
                RetModel ret = new RetModel()
                {
                    Data = null,
                    ErrCode = "",
                    ErrInfo = "",
                    Success = true
                };
                return Ok(ret);
            }
            catch (Exception ex)
            {
                return Ok(new RetModel { Success = false, ErrCode = "AdsManage003", ErrInfo = ex.Message, Data = null });
            }
        }
        /// <summary>
        /// 通过ID获取广告信息
        /// </summary>
        /// <param name="adsManageModel"></param>
        /// <param name="Token"></param>
        /// <returns></returns>
        [Route("GetAdsByID")]
        public IHttpActionResult PostGetAdsByID(int id,string Token)
        {
            try
            {
                RetModel ret = new RetModel()
                {
                    Data = null,
                    ErrCode = "",
                    ErrInfo = "",
                    Success = true
                };
                return Ok(ret);
            }
            catch (Exception ex)
            {
                return Ok(new RetModel { Success = false, ErrCode = "AdsManage004", ErrInfo = ex.Message, Data = null });
            }
        }
        /// <summary>
        /// 获取广告列表
        /// </summary>
        /// <param name="Token"></param>
        /// <returns></returns>
        [Route("GetAdsList")]
        public IHttpActionResult PostGetAdsList(string Token)
        {
            try
            {
                comm.CheckInfo(Token);
                var obj = comm.adsCtrl.GetAdsList();
                RetModel ret = new RetModel()
                {
                    Data = obj,
                    ErrCode = "",
                    ErrInfo = "",
                    Success = true
                };
                return Ok(ret);
            }
            catch (Exception ex)
            {
                return Ok(new RetModel { Success = false, ErrCode = "AdsManage005", ErrInfo = ex.Message, Data = null });
            }
        }
    }
}